package com.wangmengtao.upms.util;

import com.wangmengtao.upms.dto.EasyuiTree;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: TreeNodeUtil
 * @Description: TODO
 * @Author: WangMengtao
 * @Data: 2019/6/5 17:15
 * @Version: 1.0.0
 */
public class TreeNodeUtil {
    private static final Long ZERO = 0L;
    public final static List<EasyuiTree> getFatherNode(List<EasyuiTree> easyuiTrees) {
        List<EasyuiTree> easyuiTreeList = new ArrayList<EasyuiTree>();
        for (EasyuiTree easyuiTree : easyuiTrees) {
            if (ZERO.equals(easyuiTree.getParentId())) {
                easyuiTree.setChildren(getChildrenNode(easyuiTree.getId(), easyuiTrees));
                easyuiTree.setState("open");
                easyuiTreeList.add(easyuiTree);
            }
        }
        return easyuiTreeList;
    }

    public final static List<EasyuiTree> getChildrenNode(Long parentId, List<EasyuiTree> easyuiTrees) {
        List<EasyuiTree> easyuiTreeList = new ArrayList<EasyuiTree>();
        for (EasyuiTree easyuiTree : easyuiTrees) {
            if (easyuiTree.getParentId().equals(parentId)) {
                easyuiTree.setChildren(getChildrenNode(easyuiTree.getId(), easyuiTrees));
                easyuiTreeList.add(easyuiTree);
            }
        }
        return easyuiTreeList;
    }
}
